<!DOCTYPE html>
<html>
<head lang="zh">
    <meta charset="UTF-8">
    <title>${accId???string("编辑", "添加")}账户信息</title>
<#include "admin/common.ftl"/>
<#include "admin/permission.ftl"/>
    <style type="text/css">
        #fm table tr td:first-child {text-align:right}
    </style>
</head>
<body>
<form id="fm" action="${base}/admin/account/save" method="post">
    <input type="hidden" name="id" value="${accId!}">
    <table cellpadding="5">
        <tr>
            <td>账号:</td>
            <td><input class="easyui-textbox ehome-input" id="accName" name="accName" value="<#if account??>${account.accName}</#if>"
                       data-options="required:true,
                       validType:{
                           maxLength:[20],
                           engNum:true,
                           remote:['${base}/admin/account/existsName?accId=${accId!}', 'name']
                       }"/></td>
        </tr>
        <tr>
            <td>密码:</td>
            <td><input class="easyui-textbox ehome-input" id="password" name="password" value="<#if account??>${account.password}</#if>"
                       data-options="required:true,type:'password',
                       validType:{
                           maxLength:[20],
                           engNum:true,
                           password:true
                       }"></td>
        </tr>
        <tr>
            <td>昵称:</td>
            <td><input class="easyui-textbox ehome-input" id="sign" name="nickName" value="<#if account??>${account.nickName}</#if>"
                       data-options="required:true,validType:'maxLength[50]'"/></td>
        </tr>
        <tr>
            <td>手机号:</td>
            <td><input class="easyui-textbox ehome-input" id="sign" name="phone" value="<#if account??>${account.phone}</#if>"
                       data-options="required:true,validType:'mobile'"/></td>
        </tr>
        <tr>
            <td>描述:</td>
            <td><input class="easyui-textbox ehome-textarea" id="description" name="description"
                       data-options="multiline:true,value:'<#if account??>${account.description!}</#if>',validType:'maxLength[200]'"/></td>
        </tr>
    </table>

    <div style="width: 450px;text-align: center">
        <a id="btnSave" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ehome-standard-save',onClick:save">保 存</a>&nbsp;
        <a id="btnCancel" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ehome-standard-cancel',onClick:closeLayer">取 消</a>
    </div>
</form>

<script src="${base}/static/jquery-plugins/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function() {
        rewriteDomElementStyle();
        initEscEvent();
    });

    <#if hasSave == "true">
    // 保存
    function save() {
        var fm = $("#fm");
        if (fm.form("validate")) {
            fm.ajaxSubmit({
                success: function (data) {
                    var result = JSON.parse(data);
                    var status = result.status;
                    if (status == "success") {
                        parent.reloadGrid();
                        closeLayer();
                    }
                }
            });
        }
    }
    </#if>

    // 关闭当前layer页面
    function closeLayer() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    // 初始化ESC事件
    function initEscEvent() {
        // 使一个可见元素先focus
        $("#name").parent().find("span input:not('hidden')").focus();
        document.onkeyup = function (e) {
            e = e || window.event;
            var code = e.which || e.keyCode;
            if (code == 27) {
                closeLayer();
            }
        }
    }
</script>
</body>
</html>